home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Developer Essentials / DTS Sample Code / Macintosh Sample Code / SC.014.CPlusTESample / Application.h < prev    next >
Encoding:
C/C++ Source or Header  |  1990-04-30  |  5.5 KB  |  173 lines  |  [TEXT/MPS ]

  1. /*------------------------------------------------------------------------------------------
  2.  
  3.     Program:    CPlusTESample 2.0
  4.     File:        Application.h
  5.     Uses:       AppLib.h
  6.  
  7.     by Andrew Shebanow
  8.     of Apple Macintosh Developer Technical Support
  9.  
  10.     Copyright © 1989-1990 Apple Computer, Inc.
  11.     All rights reserved.
  12.  
  13. ------------------------------------------------------------------------------------------*/
  14.  
  15. #ifndef __APPLICATION__
  16. #define __APPLICATION__
  17.  
  18. // Include necessary interface files
  19. #ifndef __STRING__
  20. #include <String.h>
  21. #endif
  22.  
  23. #ifndef __TYPES__
  24. #include <Types.h>
  25. #endif
  26. #ifndef __DESK__
  27. #include <Desk.h>
  28. #endif
  29. #ifndef __EVENTS__
  30. #include <Events.h>
  31. #endif
  32. #ifndef __OSUTILS__
  33. #include <OSUtils.h>
  34. #endif
  35.  
  36. // we need resource ids
  37. #ifndef __APPLIB__
  38. #include "AppLib.h"
  39. #endif
  40.  
  41. // we need the exceptions code
  42. #ifndef __EXCEPTIONS__
  43. #include "Exceptions.h"
  44. #endif
  45.  
  46. class TDocument;
  47. class TDocumentList;
  48.  
  49. // YNCResult is a type used to indicate a result from
  50. // a user operation. YNC means yes/no/cancel, but yes
  51. // and no can also have synonyms like Save and Discard.
  52. enum YNCResult { yesResult, noResult, cancelResult };
  53.  
  54. /*
  55.     TApplication:
  56.  
  57.     This is our class which implements a basic Macintosh style program,
  58.     including a MultiFinder-aware event loop.
  59. */
  60.  
  61. // we derive from handle object to prevent fragmentation
  62. class TApplication : public HandleObject {
  63. private:
  64.     static OSType fCreator;
  65.  
  66. public:
  67.     // Our constructor
  68.     TApplication(OSType creator);
  69.  
  70.     // process finder arguments
  71.     virtual void    ProcessArgs();
  72.  
  73.     // Call this routine to start event loop running
  74.     // It will not return until the user quits the application (via a call
  75.     // to DoQuit, below)
  76.     virtual void    EventLoop();
  77.  
  78.     // Utility routines you can use
  79.     static Boolean            TrapAvailable(short tNumber,TrapType tType);
  80.         // Is trap implemented???
  81.     inline TDocumentList*    DocList() { return fDocList; };
  82.     static OSType            GetCreator() { return fCreator; };
  83.     static void                WDToDirID(short wdRefNum, short& vRefNum, long& dirID);
  84.         // utility routine to convert a working directory to a vRefNum/dirID pair
  85.  
  86. protected:
  87.     virtual long    StackNeeded() { return 0; };
  88.         // Returns total stack space required in bytes.
  89.         // Returns 0 by default, which tells the initialization code
  90.         // to use the default stack size.
  91.     virtual long    HeapNeeded() { return 0; };
  92.         // Returns total heap space required in bytes.
  93.         // Returns 0 by default, which tells the initialization code
  94.         // to use whatever heap size is given.
  95.  
  96.     // called by EventLoop to process an individual event
  97.     virtual void    ProcessEvent();
  98.  
  99.     // Loop control methods you may need to override
  100.     virtual void    SetUp() {};                // Run before event loop starts
  101.     virtual void    DoIdle() {};            // idle time handler (blink caret, background tasks)
  102.     virtual void    AdjustMenus() {};        // menu updater routine
  103.  
  104.     // event handlers you shouldn't need to override in a typical application
  105.     virtual void    DoOSEvent();
  106.         // Calls DoSuspend, DoResume and DoIdle as apropos
  107.     virtual void    DoMouseDown();
  108.         // Calls DoContent, DoGrow, DoZoom, etc
  109.     virtual void    DoKeyDown();
  110.         // also called for autokey events
  111.     virtual void    DoActivateEvt();
  112.         // handles setup, and calls DoActivate (below)
  113.     virtual void    DoUpdateEvt();
  114.         // handles setup, and calls DoUpdate (below)
  115.     virtual void    DoMouseInSysWindow() { SystemClick(&fTheEvent, fWhichWindow); };
  116.     virtual void    DoDrag();
  117.     virtual void    DoGoAway();
  118.         // handles setup, and calls TDocument::DoClose
  119.     virtual void    DoQuit(Boolean askUser, YNCResult defaultResult);
  120.  
  121.     // handlers you MUST override for functionality:
  122.     virtual void    AdjustCursor() = 0;
  123.         // cursor adjust routine, should setup mouseRgn
  124.     virtual void    DoMenuCommand(short menuID, short menuItem) = 0;
  125.     virtual void    DoNew() = 0;
  126.     virtual void    DoOpen() = 0;
  127.     virtual void    OpenADoc(short vRefNum, long dirID,
  128.                              StringPtr fName, OSType fType) = 0;
  129.  
  130.     // called by OSEvent (just calls DoActivate by default, so no clip conversion
  131.     // is done). If you want to convert clipboard, override these routines
  132.     virtual void    DoSuspend(Boolean doClipConvert);
  133.     virtual void    DoResume(Boolean doClipConvert);
  134.  
  135.     // If you have an app that needs to know about these, override them
  136.     virtual void    DoMouseUp() {};
  137.     virtual void    DoDiskEvt() {};
  138.  
  139.     // Utility routines you need to provide to do MultiFinder stuff
  140.     virtual unsigned long SleepVal() { return 0; };
  141.         // how long to sleep in WaitNextEvent
  142.  
  143.     // useful variables
  144.     Boolean            fHaveWaitNextEvent;        // true if we have WaitNextEvent trap
  145.     Boolean            fDone;                    // set to true when we are ready to quit
  146.     Boolean            fOnSystem7;                // running system 7 or better
  147.     EventRecord        fTheEvent;                // our event record
  148.     WindowPtr        fWhichWindow;            // currently active window
  149.     Boolean            fInBackground;            // true if our app is suspended
  150.     Boolean            fWantFrontClicks;        // true if we want front clicks
  151.     RgnHandle        fMouseRgn;                // mouse moved region (set it in your DoIdle)
  152.     TDocument*        fCurDoc;                // currently active document (if any)
  153.     TDocumentList*    fDocList;                // the list of documents
  154. };
  155.  
  156. // some other handy utility routines, not actually a part of application class
  157.  
  158. // display alert, using specified error STR# resource and error code as index
  159. void AlertUser(short errResID, short errCode);
  160. // call AlertUser to display error message, then quit...
  161. void BigBadError(short errResID, short errCode);
  162. Boolean LookupErrorString(short value, short resID, StringPtr str);
  163.  
  164. // useful state checking Booleans (mostly for System 7 compatibility)
  165. extern Boolean gHaveColorQD;
  166.  
  167. inline void CopyPString(StringPtr to, StringPtr from)
  168. {
  169.     memcpy(to,from,(size_t) (from[0] & 0x0ff) + 1);
  170. }
  171.  
  172. #endif
  173.